const fs = require('fs')
const chalk = require('chalk')
const http = require('http')
const url = require('url')
const PORT = 2222

const server = http.createServer()
server.on("request",(req,res)=>{
	var objUrl = url.parse(req.url,true);
  fs.readFile(`./mock/${objUrl.path}`, (err, buf) => {
    res.setHeader('Access-Control-Allow-Origin', '*')
    res.setHeader("content-type", 'application/json; charset=utf-8')
    res.end(buf)
  })
})


server.listen(PORT)
console.log(chalk.green('localhost:2222服务运行中...'));